<template>
  <div>
    <!--导航栏开始-->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>生产管理</el-breadcrumb-item>
      <el-breadcrumb-item>工艺流程</el-breadcrumb-item>
    </el-breadcrumb>
    <!--导航栏结束-->
    <!--搜索栏开始-->
    <el-form
      style="margin-top: 15px"
      :inline="true"
      :model="queryroute"
      class="demo-form-inline"
    >
      <el-row>
        <el-col :span="8">
          <el-form-item label="工艺路线编号">
            <el-input
              v-model="queryroute.routeCode"
              placeholder="请输入工艺路线编号"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="工艺路线名称">
            <el-input
              v-model="queryroute.routeName"
              placeholder="请输入工艺路线名称"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否启用">
            <el-input
              v-model="queryroute.enableFlag"
              placeholder="请输入是否启用"
              clearable
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="searchRoute">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="resetRoute">重置</el-button>
      </el-form-item>
    </el-form>
    <!--搜索栏结束-->
    <!--功能栏开始-->
    <el-button @click="addRoute" type="primary">
      <el-icon>
        <Plus />
      </el-icon>
      新增
    </el-button>
    <el-button type="warning">
      <el-icon>
        <EditPen />
      </el-icon>
      导出</el-button
    >
    <!--功能栏结束-->
    <!--列表开始-->
    <el-table
      ref="routeTable"
      :data="routes"
      max-height="800px"
      stripe="true"
      border="true"
      style="width: 100%; margin-top: 10px"
    >
      <el-table-column align="center" label="工艺路线编码" property="routeCode">
        <!-- <template #default="scope">
          <el-link type="success" @click="show(scope.row)">
            {{ scope.row.routeCode }}
          </el-link>
        </template> -->
      </el-table-column>
      <el-table-column
        align="center"
        label="工艺路线名称"
        property="routeName"
      />
      <el-table-column
        align="center"
        label="工艺路线说明"
        property="routeDesc"
      />
      <el-table-column align="center" label="是否启用" property="enableFlag">
        <template #default="scope">
          <!-- scope.row 就是整行数据-->
          <el-tag v-if="scope.row.enableFlag == 'Y'" class="ml-2" type="success"
            >是</el-tag
          >
          <el-tag v-if="scope.row.enableFlag == 'N'" class="ml-2" type="primary"
            >否</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column align="center" label="备注" property="remark" />
      <el-table-column width="150" align="center" label="操作">
        <template #default="scope">
          <el-button size="small" @click="updaterow(scope.row)"
            ><el-icon>
              <EditPen /> </el-icon
            >修改</el-button
          >
          <el-button size="small" @click="deleterow(scope.row)"
            ><el-icon>
              <Delete /> </el-icon
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!--列表结束-->
    <!--分页开始-->
    <el-pagination
      style="margin-top: 15px"
      :page-size="routeLimit"
      :pager-count="routeMaxPage"
      @current-change="changePage"
      layout="prev, pager, next"
      :total="routeTotal"
    />
    <!--分页结束-->
    <!--新增工艺流程开始-->
    <!--新增工艺设置的弹窗设置开始-->
    <el-dialog
      v-model="addRouteDialogVisible"
      title="添加生产工序"
      width="600"
      align-center
    >
      <el-form
        label-width="100px"
        :model="addRouteData"
        style="max-width: 460px"
      >
        <el-form-item label="编码">
          <el-input
            v-model="addRouteData.routeCode"
            placeholder="请输入工艺路线编码"
          />
          <el-switch
            @change="autoGenRouteCode"
            v-model="autoRouteCode"
            class="ml-2"
            style="
              --el-switch-on-color: #13ce66;
              --el-switch-off-color: #ff4949;
            "
          />
        </el-form-item>
        <el-form-item label="名称">
          <el-input
            v-model="addRouteData.routeName"
            placeholder="请输入工艺路线名称"
          />
        </el-form-item>
        <el-form-item label="是否启用">
          <el-radio-group v-model="addRouteData.enableFlag" class="ml-4">
            <el-radio label="1" size="large">是</el-radio>
            <el-radio label="2" size="large">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="说明">
          <el-input
            type="textarea"
            v-model="addRouteData.routeDesc"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            type="textarea"
            v-model="addRouteData.remark"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="cancelAddData">取消</el-button>
          <el-button type="primary" @click="doAddData"> 提交 </el-button>
        </span>
      </template>
    </el-dialog>
    <!--新增工艺设置的弹窗设置结束-->
    <!--新增工艺流程结束-->
    <!--删除工艺流程弹窗开始-->
    <el-dialog v-model="deleteTheTip" title="系统提示" width="600" align-center>
      <template #footer>
        <span class="dialog-footer">
          <el-alert title="是否删除此行数据" type="error" />
          <el-button @click="canceldelete">取消</el-button>
          <el-button type="primary" @click="confirmdelete">提交</el-button>
        </span>
      </template>
    </el-dialog>
    <!--删除工艺流程弹窗结束-->
    <!--编辑弹窗设置开始-->
    <el-dialog
      v-model="updateRouteDialogVisible"
      title="编辑工艺流程"
      width="600"
      align-center
    >
      <el-form
        label-width="100px"
        :model="updateRouteData"
        style="max-width: 460px"
      >
        <el-form-item label="工艺名称">
          <el-input
            v-model="updateRouteData.routeName"
            placeholder="请输入工艺名称"
          />
        </el-form-item>
        <el-form-item label="是否启用">
          <el-radio-group v-model="updateRouteData.enableFlag" class="ml-4">
            <el-radio label="1" size="large">是</el-radio>
            <el-radio label="2" size="large">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="说明">
          <el-input
            type="textarea"
            v-model="updateRouteData.routeDesc"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            type="textarea"
            v-model="updateRouteData.remark"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
    <el-tab-pane label="组成工序" name="first"> <el-button @click="addProRouteProcess" type="primary">
        <el-icon>
          <Plus />
        </el-icon>
        新增
      </el-button>    
      <!--功能栏结束-->
      <!--列表开始-->
      <el-table
        ref="routeProcessTable"
        :data="routeProcess"
        max-height="800px"
        stripe="true"
        border="true"
        style="width: 100%; margin-top: 10px"
      >
        <el-table-column align="center" label="序号" property="orderNum" />
        <el-table-column align="center" label="工序编码" property="processCode" />
        <el-table-column align="center" label="工序名称" property="processName" />
        <el-table-column align="center" label="下一道工序" property="nextProcessName" />
        <el-table-column align="center" label="与下一道工序关系" property="linkType" />
        <el-table-column align="center" label="关键工序" property="keyFlag" />
        <el-table-column align="center" label="准备时间" property="defaultPreTime" />
        <el-table-column align="center" label="等待时间" property="defaultSugTime" />
        <el-table-column align="center" label="甘特图显示颜色" property="colorCode" >
          <template #default="scope">
            <el-color-picker v-model="scope.row.colorCode" disabled/>
                </template>
        </el-table-column>
        <el-table-column width="150" align="center" label="操作">
          <template #default="scope">
            <el-button size="small" @click="updateRouteProcess(scope.row)"
              ><el-icon>
                <EditPen /> </el-icon
              >修改</el-button
            >
            <el-button size="small" @click="deleteRouteProcess(scope.row)"
              ><el-icon>
                <Delete /> </el-icon
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!--列表结束-->
      <!--分页开始-->
      <el-pagination
        style="margin-top: 15px"
        :page-size="routeProcessLimit"
        :pager-count="routeProcessMaxPage"
        @current-change="changePage2"
        layout="prev, pager, next"
        :total="routeProcessTotal"
      />
      <!--分页结束-->
      </el-tab-pane>
    <el-tab-pane label="关联产品" name="second">    
      <!--搜索栏开始-->
    <el-form
      style="margin-top: 15px"
      :inline="true"
      :model="queryrouteProduct"
      class="demo-form-inline"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="产品物料编码">
            <el-input
              v-model="queryrouteProduct.itemCode"
              placeholder="请输入产品物料编码"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品物料名称">
            <el-input
              v-model="queryrouteProduct.itemName"
              placeholder="请输入产品物料名称"
              clearable
            />
          </el-form-item>
        </el-col>
      
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="searchRouteProduct">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="resetRouteProduct">重置</el-button>
      </el-form-item>
    </el-form>
    <!--搜索栏结束-->
    <!--功能栏开始-->
    <el-button @click="addRouteProduct" type="primary">
      <el-icon>
        <Plus />
      </el-icon>
      新增
    </el-button>
    <el-button type="warning">
      <el-icon>
        <EditPen />
      </el-icon>
      导出</el-button
    >
    <!--功能栏结束-->
    <!--列表开始-->
    <el-table
      ref="routeProductTable"
      :data="routeProduct"
      max-height="800px"
      stripe="true"
      border="true"
      style="width: 100%; margin-top: 10px"
    >
      <el-table-column align="center" label="产品物料编码" property="itemCode"/>
      <el-table-column
        align="center"
        label="产品物料名称"
        property="itemName"
      />
      <el-table-column
        align="center"
        label="规格型号"
        property="specification"
      />
      <el-table-column align="center" label="单位" property="unitOfMeasure"/>
        
      <el-table-column width="150" align="center" label="操作">
        <template #default="scope">
          <el-button size="small" @click="updateRouteProduct(scope.row)"
            ><el-icon>
              <EditPen /> </el-icon
            >修改</el-button
          >
          <el-button size="small" @click="deleteRouteProduct(scope.row)"
            ><el-icon>
              <Delete /> </el-icon
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!--列表结束-->
    <!--分页开始-->
    <el-pagination
      style="margin-top: 15px"
      :page-size="routeProductLimit"
      :pager-count="routeProductMaxPage"
      @current-change="changePage3"
      layout="prev, pager, next"
      :total="routeProductTotal"
    />
    <!--分页结束--></el-tab-pane>
  </el-tabs>
     
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="cancelupdateRouteDialogVisible">取消</el-button>
          <el-button type="primary" @click="doupdateupdateRouteDialogVisible">
            提交
          </el-button>
        </span>
      </template>
    </el-dialog>
    <!--编辑弹窗设置结束-->
    <!--新增工艺组成弹窗开始-->
    <el-dialog
      v-model="addProRouteProcessDialogVisible"
      title="添加工艺组成弹窗"
      width="500px"
      align-center
    >
      <el-form
        label-width="200px"
        :model="addProRouteProcessData"
        style="max-width: 600px"
      >
        <el-form-item label="顺序编号">
          <el-input-number
            v-model="addProRouteProcessData.orderNum"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="工序">
          <el-select
            v-model="addProRouteProcessData.processName"
            clearable
            placeholder="请选择工序"
          >
            <el-option
              v-for="item in processData"
              :key="item.processId"
              :label="item.processName"
              :value="item.processName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="与下一道工序的关系" >
          <el-select v-model="addProRouteProcessData.linkType" placeholder="请选择与下一道工序的关系">
            <el-option label="S-to-S" value="S-to-S" />
            <el-option label="F-to-F" value="F-to-F" />
            <el-option label="S-to-F" value="S-to-F" />
            <el-option label="F-to-S" value="F-to-S" />
          </el-select>
        </el-form-item>
        <el-form-item label="甘特图颜色"> 
          <el-color-picker v-model="addProRouteProcessData.colorCode" />
        </el-form-item>
        <el-form-item label="是否关键工序"> 
          <el-select v-model="addProRouteProcessData.keyFlag" placeholder="请选择是否关键工序">
            <el-option label="是" value="否" />
            <el-option label="否" value="否" />
          </el-select>
        </el-form-item>
        <el-form-item label="准备时间"> 
          <el-input-number
            v-model="addProRouteProcessData.defaultPreTime"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="等待时间"> 
          <el-input-number
            v-model="addProRouteProcessData.defaultSugTime"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            type="textarea"
            v-model="addProRouteProcessData.remark"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="cancelProRouteProcessDialogVisible">取消</el-button>
          <el-button type="primary" @click="doAddProRouteProcessData()">
            提交
          </el-button>
        </span>
      </template>
    </el-dialog>
    <!--新增工艺组成弹窗结束-->
    <!--编辑工艺组成的弹窗开始-->
    <el-dialog
      v-model="updateRouteProcessDialogVisible"
      title="编辑工艺组成"
      width="600"
      align-center
    >
    <el-form
        label-width="200px"
        :model="updateRouteProcessData"
        style="max-width: 600px"
      >
        <el-form-item label="顺序编号">
          <el-input-number
            v-model="updateRouteProcessData.orderNum"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="工序">
          <el-select
            v-model="updateRouteProcessData.processName"
            clearable
            placeholder="请选择工序"
          >
            <el-option
              v-for="item in processData"
              :key="item.processId"
              :label="item.processName"
              :value="item.processName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="与下一道工序的关系" >
          <el-select v-model="updateRouteProcessData.linkType" placeholder="请选择与下一道工序的关系">
            <el-option label="S-to-S" value="S-to-S" />
            <el-option label="F-to-F" value="F-to-F" />
            <el-option label="S-to-F" value="S-to-F" />
            <el-option label="F-to-S" value="F-to-S" />
          </el-select>
        </el-form-item>
        <el-form-item label="甘特图颜色"> 
          <el-color-picker v-model="updateRouteProcessData.colorCode" />
        </el-form-item>
        <el-form-item label="是否关键工序"> 
          <el-select v-model="updateRouteProcessData.keyFlag" placeholder="请选择是否关键工序">
            <el-option label="是" value="否" />
            <el-option label="否" value="否" />
          </el-select>
        </el-form-item>
        <el-form-item label="准备时间"> 
          <el-input-number
            v-model="updateRouteProcessData.defaultPreTime"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="等待时间"> 
          <el-input-number
            v-model="updateRouteProcessData.defaultSugTime"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            type="textarea"
            v-model="updateRouteProcessData.remark"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>

      <template #footer>
        <span class="dialog-footer">
          <el-button @click="cancelupdateRouteProcessDialogVisible">取消</el-button>
          <el-button type="primary" @click="doupdateRouteProcessDialogVisible"> 提交 </el-button>
        </span>
      </template>
    </el-dialog>
    <!--编辑工艺步骤的弹窗设置的结束-->
    <!--编辑工艺组成的弹窗结束-->
    <!--新增关联产品的弹窗设置开始-->
    <el-dialog
      v-model="addProRouteProductDialogVisible"
      title="添加关联产品"
      width="500px"
      align-center
    >
      <el-form
        label-width="200px"
        :model="addProRouteProduct"
        style="max-width: 600px"
      >
      <el-form-item label="产品物料Id">
          <el-input
            v-model="addProRouteProduct.itemId"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="产品物料编码">
          <el-input
            v-model="addProRouteProduct.itemCode"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="产品物料名称">
          <el-input
            v-model="addProRouteProduct.itemName"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="单位" >
          <el-input
            v-model="addProRouteProduct.unitOfMeaSure"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="规格型号"> 
          <el-input
            v-model="addProRouteProduct.specification"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="备注"> 
          <el-input
            v-model="addProRouteProduct.remark"
            :min="1"
            :max="1000"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="cancelProRouteProduct">取消</el-button>
          <el-button type="primary" @click="doAddProRouteProduct">
            提交
          </el-button>
        </span>
      </template>
    </el-dialog>
    <!--修改关联产品的弹窗设置结束-->
    <el-dialog
      v-model="updateProRouteProductDialogVisible"
      title="编辑关联产品"
      width="500px"
      align-center
    >
      <el-form
        label-width="200px"
        :model="updateProRouteProductData"
        style="max-width: 600px"
      >
        <el-form-item label="产品物料编码">
          <el-input
            v-model="updateProRouteProductData.itemCode"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="产品物料名称">
          <el-input
            v-model="updateProRouteProductData.itemName"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="单位" >
          <el-input
            v-model="updateProRouteProductData.unitOfMeaSure"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="规格型号"> 
          <el-input
            v-model="updateProRouteProductData.specification"
            :min="1"
            :max="1000"
          />
        </el-form-item>
        <el-form-item label="备注"> 
          <el-input
            v-model="updateProRouteProductData.remark"
            :min="1"
            :max="1000"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="cancelupdateProRouteProduct">取消</el-button>
          <el-button type="primary" @click="doAddupdateProRouteProduct">
            提交
          </el-button>
        </span>
      </template>
    </el-dialog>
    <!--修改关联产品的弹窗设置结束-->
  </div>
</template>

<script>
import routeRequest from "../../../api/pro-route";
import tools from "../../../util/tools.js";
import processRequest from "../../../api/pro-process";
import routeProcessRequest from "../../../api/pro-route-process";
import routeProductRequest from "../../../api/pro-route-product";
export default {
  data() {
    return {
      queryroute: {}, //搜索栏对象
      routes: [], //列表栏对象
      routeCurrPage: 1, // 工艺流程页的当前页码
      routeLimit: 10, // 工艺流程页的每页大小
      routeTotal: 0, // 工艺流程页的总条数
      routeMaxPage: 10, // 工艺流程页的最大页码
      addRouteDialogVisible: false, //新增提示框
      addRouteData: {}, //新增工艺流程的对象
      autoRouteCode: false, //自动生成编号
      deleteTheTip: false, //删除流程框
      deleteRouteCode: null, //要删除的编号
      updateRouteDialogVisible: false, //编辑弹窗
      updateRouteData: {}, //编辑对象
      addProRouteProcessData: {}, //新增工艺组成的对象
      addProRouteProcessDialogVisible: false, //新增工艺组成的弹窗
      processData: [],
      routeProcessCurrPage: 1, // 组成工序的当前页码
      routeProcessLimit: 10, // 组成工序页的每页大小
      routeProcessTotal: 0, // 组成工序页的总条数
      routeProcessMaxPage: 10, // 组成工序页的最大页码
      routeProcess:[],//工艺组成
      routeId:null,//工艺流程的Id
      recordId:null,//工艺组成的Id
      updateRouteProcessDialogVisible:false,//编辑工艺组成的弹窗
      updateRouteProcessData:{},//编辑工艺组成的对象
      queryrouteProduct:{},//关联产品的搜索栏对象
      routeProduct:[],//关联产品的表格
      routeProductCurrPage: 1, // 关联产品页的当前页码
      routeProductLimit: 10, // 关联产品页的每页大小
      routeProductTotal: 0, // 关联产品页的总条数
      routeProductMaxPage: 10, // 关联产品页的最大页码
      addProRouteProduct:{},//新增关联产品的组成对象
      addProRouteProductDialogVisible:false,//新增关联产品的弹窗
      updateProRouteProductDialogVisible:false,//编辑关联产品的弹窗
      updateProRouteProductData:{},//编辑关联产品的对象
    };
  },
  methods: {
    //提交修改工艺流程
    doupdateupdateRouteDialogVisible(){
      routeRequest.updateRoute(this.updateRouteData,(res) => {
        if (res.code == "200") {
          this.$message({
            message: "编辑工艺流程成功",
            type: "success",
          });
          //关闭窗体
          this.updateRouteDialogVisible=false;
          // 重新加载数据
          this.loadRoute();
          // 将updateRouteData制空
          this.updateRouteData={};
        } else if(res.code=='500'){
          this.$message({
            message: "编辑失败",
            type: "error",
          });
        }else{
          this.$message({
            message:"工艺流程名重复",
            type:"warning",
          })
        }
      });
    },
    //重置搜索关联产品
    resetRouteProduct(){
      this.queryrouteProduct={},
      routeProductRequest.list(
          this.routeProductCurrPage,
          this.routeProductLimit,
          this.queryrouteProduct,
          (res) => {
            // 设置数据
            this.routeProduct = res.data.list;
            this.routeProductTotal = res.data.total;
            this.routeProductMaxPage = res.data.pages;
          }
        );
    },
    //按条件搜索关联产品
    searchRouteProduct(){
        routeProductRequest.list(
          this.routeProductCurrPage,
          this.routeProductLimit,
          this.queryrouteProduct,
          (res) => {
            // 设置数据
            this.routeProduct = res.data.list;
            this.routeProductTotal = res.data.total;
            this.routeProductMaxPage = res.data.pages;
          }
        );
    },
    //提交关联产品
    doAddupdateProRouteProduct(){
     routeProductRequest.updateRouteProduct(this.updateProRouteProductData,(res) => {
        if (res.code == "200") {
          this.$message({
            message: "编辑关联产品成功",
            type: "success",
          });
          //关闭窗体
          this.updateProRouteProductDialogVisible=false;
          // 重新加载数据
          this.loadRouteProduct();
          // 将updateProRouteProductData制空
          this.updateProRouteProductData={};
        } else if(res.code=='500'){
          this.$message({
            message: "编辑失败",
            type: "error",
          });
        }else{
          this.$message({
            message:"关联产品名重复",
            type:"warning",
          })
        }
      });
    },
    //取消关联产品
    cancelupdateProRouteProduct(){
      this.updateProRouteProductDialogVisible=false;
      this.updateProRouteProductData={};
    },
    //编辑关联产品
    updateRouteProduct(row){
     this.updateProRouteProductDialogVisible=true;
     this.updateProRouteProductData.recordId=row.recordId;
     this.updateProRouteProductData.itemCode=row.itemCode;
     this.updateProRouteProductData.itemName=row.itemName;
     this.updateProRouteProductData.specification=row.specification;
     this.updateProRouteProductData.unitOfMeaSure=row.unitOfMeaSure;
     this.updateProRouteProductData.remark=row.remark;
    },
    //提交新增关联产品
    doAddProRouteProduct(){
      this.addProRouteProduct.routeId=this.updateRouteData.routeId;
      routeProductRequest.save(this.addProRouteProduct, (res) => {
        if (res.code == "200") {
          this.$message({
            message: "添加关联产品成功",
            type: "success",
          });
          //关闭窗体
          this.addProRouteProductDialogVisible = false;
          // 重新加载数据
          this.loadRouteProduct();
          // 将addProRouteProduct制空
          this.addProRouteProduct = {};
        } else if (res.code == "500") {
          this.$message({
            message: "添加失败",
            type: "error",
          });
          this.addRouteData = {};
        } else {
          this.$message({
            message: "关联产品重复",
            type: "warning",
          });
          this.addProRouteProcessData= {};
        }
      });
    },
    //取消新增关联产品
    cancelProRouteProduct(){
     this.addProRouteProductDialogVisible=false;
    },
    //新增关联产品
    addRouteProduct(){
    this.addProRouteProductDialogVisible=true;
    },
    //删除关联产品
    deleteRouteProduct(row)
    {
      console.log("sssssssssssssss"+row.recordId);
      routeProductRequest.deleteRouteProduct(row.recordId,(res)=>
    {
      if(res.code=="200"){
        this.$message({
          message:"删除关联产品成功",
          type:"success",
        });
      this.loadRouteProduct();
      }
      else {
        this.$message({
          message:"删除关联产品失败",
          type:"error",
        })
      }
    })
    },
    //加载关联产品
    loadRouteProduct(){
      routeProductRequest.get(this.routeProductCurrPage, this.routeProductLimit,this.routeId, (res) => {
        console.log(res.data.total);
        console.log(res.data.pages);
        // 设置数据
        this.routeProduct = res.data.list;
        this.routeProductTotal = res.data.total;
        this.routeProductMaxPage = res.data.pages;
      });
    },
    //取消编辑工艺流程
    cancelupdateRouteDialogVisible(){
      this.updateRouteDialogVisible=false;
    },
    //确认编辑工艺组成按钮
    doupdateRouteProcessDialogVisible(){
      routeProcessRequest.updateRouteProcess(this.updateRouteProcessData,(res) => {
        if (res.code == "200") {
          this.$message({
            message: "编辑工艺组成成功",
            type: "success",
          });
          //关闭窗体
          this.updateRouteProcessDialogVisible=false;
          // 重新加载数据
          this.loadRouteProcess();
          // 将updateProcessData制空
          this.updateRouteProcessData={};
        } else if(res.code=='500'){
          this.$message({
            message: "编辑失败",
            type: "error",
          });
        }else{
          this.$message({
            message:"工艺组成重复",
            type:"warning",
          })
        }
      });
    },
    //取消编辑工艺组成按钮
    cancelupdateRouteProcessDialogVisible(){
      this.updateRouteProcessDialogVisible=false;
      this.updateRouteProcessData={}
    },
    //编辑工艺组成
    updateRouteProcess(row){
      this.updateRouteProcessData.recordId=row.recordId;
      this.updateRouteProcessData.orderNum=row.orderNum;
      this.updateRouteProcessData.processName=row.processName;
      this.updateRouteProcessData.linkType=row.linkType;
      this.updateRouteProcessData.colorCode=row.colorCode;
      this.updateRouteProcessData.keyFlag=row.keyFlag;
      this.updateRouteProcessData.defaultPreTime=row.defaultPreTime;
      this.updateRouteProcessData.defaultSugTime=row.defaultSugTime;
      this.updateRouteProcessData.remark=row.remark; 
      this.updateRouteProcessDialogVisible=true;
    },
    //删除工艺组成
    deleteRouteProcess(row){
    routeProcessRequest.deleteRouteProcess(row.recordId,(res)=>
    {
      console.log("sddddd0"+row.recordId);
      if(res.code=="200"){
        this.$message({
          message:"删除工艺组成成功",
          type:"success",
        });
      this.loadRouteProcess();
      }
      else {
        this.$message({
          message:"删除工艺组成失败",
          type:"error",
        })
      }
    })
    },
    //加载工艺组成
    loadRouteProcess(){
      routeProcessRequest.get(this.routeProcessCurrPage, this.routeProcessLimit,this.routeId, (res) => {
        console.log(res.data.total);
        console.log(res.data.pages);
        // 设置数据
        this.routeProcess = res.data.list;
        this.routeProcessTotal = res.data.total;
        this.routeProcessMaxPage= res.data.pages;
      });
    },
    //提交新增工艺组成
    doAddProRouteProcessData(){
      this.addProRouteProcessData.routeId=this.updateRouteData.routeId;
      routeProcessRequest.save(this.addProRouteProcessData, (res) => {
        if (res.code == "200") {
          this.$message({
            message: "添加工艺组成成功",
            type: "success",
          });
          //关闭窗体
          this.addProRouteProcessDialogVisible = false;
          // 重新加载数据
          this.loadRouteProcess();
          // 将addProRouteProcessData制空
          this.addProRouteProcessData = {};
        } else if (res.code == "500") {
          this.$message({
            message: "添加失败",
            type: "error",
          });
          this.addRouteData = {};
        } else {
          this.$message({
            message: "工艺名称重复",
            type: "warning",
          });
          this.addProRouteProcessData= {};
        }
      });
    },
    //取消新增工艺组成
    cancelProRouteProcessDialogVisible(){
      this.addProRouteProcessDialogVisible=false;
    },
    //新增工艺组成
    addProRouteProcess() {
      this.addProRouteProcessDialogVisible = true;
    },
    //编辑工艺流程
    updaterow(row) {
      this.routeId=row.routeId;
      this.updateRouteData.routeId=row.routeId;
      this.updateRouteData.routeName = row.routeName;
      this.updateRouteData.routeDesc = row.routeDesc;
      this.updateRouteData.remark = row.remark;
      this.updateRouteDialogVisible = true;
      this.loadRouteProcess();
      this.loadRouteProduct();
    },
    //确认删除工艺流程
    confirmdelete() {
      routeRequest.deleteRoute(this.deleteRouteCode, (res) => {
        if (res.code == "200") {
          this.loadRoute();
          this.deleteTheTip = false;
        }
      });
      this.deleteTheTip = false;
    },
    //取消删除工艺流程
    canceldelete() {
      this.deleteTheTip = false;
    },
    //删除工艺流程
    deleterow(row) {
      this.deleteTheTip = true;
      this.deleteRouteCode = row.routeCode;
    },
    //取消新增工艺流程
    cancelAddData() {
      this.addRouteDialogVisible = false;
      this.addRouteData = {};
    },
    //提交新增工艺流程
    doAddData() {
      routeRequest.save(this.addRouteData, (res) => {
        if (res.code == "200") {
          this.$message({
            message: "添加工艺流程成功",
            type: "success",
          });
          //关闭窗体
          this.addRouteDialogVisible = false;
          // 重新加载数据
          this.loadRoute();
          // 将addRouteData制空
          this.addRouteData = {};
        } else if (res.code == "500") {
          this.$message({
            message: "添加失败",
            type: "error",
          });
          this.addRouteData = {};
        } else {
          this.$message({
            message: "工序名称重复",
            type: "warning",
          });
          this.addRouteData = {};
        }
      });
    },
    //自动生成编号
    autoGenRouteCode(val) {
      if (val) {
        routeRequest.genRouteCode((res) => {
          this.addRouteData.routeCode = res.data;
        });
      }
    },
    //添加工艺流程
    addRoute() {
      this.addRouteDialogVisible = true;
    },
    //搜索重置
    resetRoute() {
      (this.queryroute = {}),
        routeRequest.list(
          this.routeCurrPage,
          this.routeLimit,
          this.queryroute,
          (res) => {
            // 设置数据
            this.routes = res.data.list;
            this.routeTotal = res.data.total;
            this.routeMaxPage = res.data.pages;
          }
        );
    },
    //分页按条件查询
    searchRoute() {
      routeRequest.list(
        this.routeCurrPage,
        this.routeLimit,
        this.queryroute,
        (res) => {
          // 设置数据
          this.routes = res.data.list;
          this.routeTotal = res.data.total;
          this.routeMaxPage = res.data.pages;
        }
      );
    },
    //分页总查询
    loadRoute() {
      routeRequest.get(this.routeCurrPage, this.routeLimit, (res) => {
        console.log(res.data.total);
        console.log(res.data.pages);
        // 设置数据
        this.routes = res.data.list;
        this.routeTotal = res.data.total;
        this.routeMaxPage = res.data.pages;
      });
    },
    //组成工艺分页
    changePage2(){
     this.routeProcessCurrPage=value;
     this.loadRouteProcess();
    },
    //关联产品分页
    changePage3() {
      this.routeProductCurrPage = value;
      this.loadRouteProduct();
    },
    
    //分页
    changePage() {
      this.routeCurrPage = value;
      this.loadRoute();
    },
    loadprocessData() {
      processRequest.selectall((res) => {
        // 设置数据
        this.processData = res.data;
      });
    },
  },
  mounted() {
    this.loadRoute();
    this.loadprocessData();
  },
};
</script>

<style></style>
